package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.pt.MallPtCashVoucher;
import com.tencreat.service.pt.IMallPtCashVoucherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 现金卷Controller
 *
 * @author tencreat
 * @date 2021-11-08
 */
@Api(tags="现金api")
//@RestController
@RequestMapping("/system/voucher")
public class MallPtCashVoucherController extends BaseController {
    //@Autowired
    private IMallPtCashVoucherService mallPtCashVoucherService;

    /**
     * 查询现金卷列表
     */
    @ApiOperation(value="查询现金卷列表")
    @PreAuthorize("@ss.hasPermi('system:voucher:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallPtCashVoucher>> list(@RequestBody  MallPtCashVoucher mallPtCashVoucher) {
        QueryWrapper<MallPtCashVoucher> wrapper = Wrappers.query(mallPtCashVoucher);
        Page<MallPtCashVoucher> page =  new Page<>(mallPtCashVoucher.getPageNum(), mallPtCashVoucher.getPageSize());
        return HttpResult.ok(mallPtCashVoucherService.page(page, wrapper));
    }

    /**
     * 导出现金卷列表
     */
    @ApiOperation(value="导出现金卷列表")
    @PreAuthorize("@ss.hasPermi('system:voucher:export')")
    @Log(title = "现金卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallPtCashVoucher mallPtCashVoucher) {
        List<MallPtCashVoucher> list = mallPtCashVoucherService.selectMallPtCashVoucherList(mallPtCashVoucher);
        ExcelUtil<MallPtCashVoucher> util = new ExcelUtil<MallPtCashVoucher>(MallPtCashVoucher.class);
        return util.exportExcel(list, "voucher");
    }

    /**
     * 获取现金卷详细信息
     */
    @ApiOperation(value="获取现金卷详细信息")
    @PreAuthorize("@ss.hasPermi('system:voucher:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallPtCashVoucher> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallPtCashVoucherService.selectMallPtCashVoucherById(id));
    }

    /**
     * 新增现金卷
     */
    @ApiOperation(value="新增现金卷")
    @PreAuthorize("@ss.hasPermi('system:voucher:add')")
    @Log(title = "现金卷", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallPtCashVoucher mallPtCashVoucher) {
        return to(mallPtCashVoucherService.insertMallPtCashVoucher(mallPtCashVoucher));
    }

    /**
     * 修改现金卷
     */
    @ApiOperation(value="修改现金卷")
    @PreAuthorize("@ss.hasPermi('system:voucher:edit')")
    @Log(title = "现金卷", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallPtCashVoucher mallPtCashVoucher) {
        return to(mallPtCashVoucherService.updateMallPtCashVoucher(mallPtCashVoucher));
    }

    /**
     * 删除现金卷
     */
    @ApiOperation(value="删除现金卷")
    @PreAuthorize("@ss.hasPermi('system:voucher:remove')")
    @Log(title = "现金卷", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallPtCashVoucherService.deleteMallPtCashVoucherByIds(ids));
    }
}
